package com.pureut.system.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.system.domain.SysVerification;
import com.pureut.system.service.ISysVerificationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 编码检验规则
 * @Param
 * @return 结果
 * @Date 22-11-18
 * @Author hl
 **/
@RestController
@RequestMapping("/verification")
public class SysVerificationController extends BaseController {


    @Resource
    private ISysVerificationService sysVerificationService;

    /**
     * 获取编码配置
     */
    @RequiresPermissions("system:verification:list")
    @GetMapping("/list")
    public TableDataInfo list(SysVerification sysVerification)
    {
        startPage();
        List<SysVerification> list = sysVerificationService.selectVerificationList(sysVerification);
        return getDataTable(list);
    }

    /**
     * 根据编码id查询详情信息
     */
    @RequiresPermissions("system:verification:query")
    @GetMapping(value = "/{verId}")
    public AjaxResult getInfo(@PathVariable long verId) {
        return AjaxResult.success(sysVerificationService.selectVerificationById(verId));
    }

    /**
     * 新增编码校验
     */
    @RequiresPermissions("system:verification:add")
    @Log(title = "新增编码校验", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody SysVerification sysVerification) throws Exception {
        return toAjax(sysVerificationService.insertVerification(sysVerification));
    }

    /**
     * 修改编码校验
     */
    @RequiresPermissions("system:verification:edit")
    @Log(title = "修改编码校验", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody SysVerification sysVerification) throws Exception {
        return toAjax(sysVerificationService.updateVerification(sysVerification));
    }

    /**
     * 删除编码校验
     */
    @RequiresPermissions("system:verification:remove")
    @Log(title = "删除编码检验", businessType = BusinessType.DELETE)
    @DeleteMapping("/{verId}")
    public AjaxResult remove(@PathVariable("verId") String verId) throws Exception {
        return toAjax(sysVerificationService.deleteVerificationById(verId));
    }


}
